package api

import (
	"net/http"

	"gitee.com/Yu-eng/Myproject/my-go-blog/common"
	"gitee.com/Yu-eng/Myproject/my-go-blog/service"
)

func (*Api) Login(w http.ResponseWriter, r *http.Request) {
	//已经够将登录成功的逻辑进行封装
	//这里根据用户登录所输入的信息进行处理
	params := common.GetRequestJsonParam(r)
	//利用断言进行转换
	userName := params["username"].(string)
	passwd := params["passwd"].(string)
	loginRes, err := service.Login(userName, passwd)
	if err != nil {
		//登录失败的逻辑
		common.Error(w, err)
		return

	}
	common.Success(w, loginRes)
}
